<?php
       class editshelf extends template{
             private $db;
           private $info;
            function __construct($db,$info)
           { 
             $this->db=$db;   
             $this->info=$info;
             $this->db->get_connect();
           }
           function getshelfbyid($shelfid)
           {
            $sql="
            SELECT
            tb_shelf.*
            FROM
            tb_shelf
            where  tb_shelf.shelfid=$shelfid
            ";
            $arrayshelf=$this->db->db_set_recordset($sql);
            
            if($arrayshelf['0']['shelfid'])
            {
            $arraydata['shelf']=$arrayshelf[0];
            
            
            $sql=" SELECT * FROM `tb_banner` where tb_banner.shelfid=$shelfid order by sort asc ";
            $arraybanner=$this->db->db_set_recordset($sql); 
            
            
            $arraydata['banner']=$arraybanner;
            
            
            
            $sql=" SELECT * FROM `tb_banner_library` where tb_banner_library.shelfid=$shelfid order by sort asc ";
            $arraybanner=$this->db->db_set_recordset($sql); 
            
            
            $arraydata['bannerlibrary']=$arraybanner;
            
            
            $sql=" SELECT * FROM `tb_user` where tb_user.shelfid=$shelfid  order by userid asc";
            
            $arrayuser=$this->db->db_set_recordset($sql);
            
            
            $arraydata['user']=$arrayuser;
            
            
            
            $sql=" SELECT * FROM `tb_cat` where tb_cat.shelfid=$shelfid ";
            $arraycat=$this->db->db_set_recordset($sql);
            
            
            $arraydata['cat']=$arraycat;
            
            
            
            $sql=" SELECT * FROM `tb_tag` where tb_tag.shelfid=$shelfid order by updatedate desc ";
            $arraycat=$this->db->db_set_recordset($sql);
            
            
            $arraydata['tag']=$arraycat;
            
            $this->db->closedb(); 
            }else{
            
            
            $this->db->closedb(); 
            header("Location: ".baseinfo.'/portalshelf');
            }
            
            
            
            return      $arraydata;
              
           }
           function view(){ 
           
             if($_GET['shelfid'])
              {
              $databird['editshelf']=$this->getshelfbyid($_GET['shelfid']);
              $databird['label']="บันทึก"; 
              $this->setdata($databird);
              $this->load('createshelf');
              
              
              
              }else
              {
              
              header("Location: ".baseinfo.'/portalshelf'); 
              }
           
           }
        
        
        }
?>
